# from http://www.refactoring.com/catalog/index.html
rejected="""
<li><a href = 'changeBidirectionalAssociationToUnidirectional.html'>Change Bidirectional Association to Unidirectional</a> </li> 
<li><a href = 'changeUnidirectionalAssociationToBidirectional.html'>Change Unidirectional Association to Bidirectional</a> <img src = 'updated.gif'></img></li> 
<li><a href = 'eliminateInterEntityCommunication.html'>Eliminate Inter-Entity Bean Communication</a> <i>(Link Only)</i></li> 
"""
src = """
<li><a href = 'addParameter.html'>Add Parameter</a> </li> 
 
<li><a href = 'changeReferenceToValue.html'>Change Reference to Value</a> </li> 
  
<li><a href = 'changeValueToReference.html'>Change Value to Reference</a> </li> 
 
<li><a href = 'collapseHierarchy.html'>Collapse Hierarchy</a> </li> 
 
<li><a href = 'consolidateConditionalExpression.html'>Consolidate Conditional Expression</a> </li> 
 
<li><a href = 'consolidateDuplicateConditionalFragments.html'>Consolidate Duplicate Conditional Fragments</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'convertDynamicToStaticConstruction.html'>Convert Dynamic to Static Construction</a> <i>by Gerard M. Davison</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'convertStaticToDynamicConstruction.html'>Convert Static to Dynamic Construction</a> <i>by Gerard M. Davison</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'decomposeConditional.html'>Decompose Conditional</a> </li> 
 
<li><a href = 'duplicateObservedData.html'>Duplicate Observed Data</a> </li> 
  
<li><a href = 'encapsulateCollection.html'>Encapsulate Collection</a> </li> 
 
<li><a href = 'encapsulateDowncast.html'>Encapsulate Downcast</a> </li> 
 
<li><a href = 'encapsulateField.html'>Encapsulate Field</a> </li> 
 
<li><a href = 'extractClass.html'>Extract Class</a> </li> 
 
<li><a href = 'extractInterface.html'>Extract Interface</a> </li> 
 
<li><a href = 'extractMethod.html'>Extract Method</a> </li> 
 
<li><a href = 'extractPackage.html'>Extract Package</a> <i>by Gerard M. Davison</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'extractSubclass.html'>Extract Subclass</a> </li> 
 
<li><a href = 'extractSuperclass.html'>Extract Superclass</a> </li> 
 
<li><a href = 'formTemplateMethod.html'>Form Template Method</a> </li> 
 
<li><a href = 'hideDelegate.html'>Hide Delegate</a> </li> 
 
<li><a href = 'hideMethod.html'>Hide Method</a> </li> 
 
<li><a href = 'hidePresentationTierDetails.html'>Hide presentation tier-specific details from the business tier</a> <i>(Link Only)</i></li> 
 
<li><a href = 'inlineClass.html'>Inline Class</a> </li> 
 
<li><a href = 'inlineMethod.html'>Inline Method</a> </li> 
 
<li><a href = 'inlineTemp.html'>Inline Temp</a> </li> 
 
<li><a href = 'introduceAController.html'>Introduce A Controller</a> <i>(Link Only)</i></li> 
 
<li><a href = 'introduceAssertion.html'>Introduce Assertion</a> </li> 
 
<li><a href = 'introduceBusinessDelegate.html'>Introduce Business Delegate</a> <i>(Link Only)</i></li> 
 
<li><a href = 'introduceExplainingVariable.html'>Introduce Explaining Variable</a> </li> 
 
<li><a href = 'introduceForeignMethod.html'>Introduce Foreign Method</a> </li> 
 
<li><a href = 'introduceLocalExtension.html'>Introduce Local Extension</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'introduceNullObject.html'>Introduce Null Object</a> </li> 
 
<li><a href = 'introduceParameterObject.html'>Introduce Parameter Object</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'introduceSynchronizerToken.html'>Introduce Synchronizer Token</a> <i>(Link Only)</i></li> 
 
<li><a href = 'localizeDisparateLogic.html'>Localize Disparate Logic</a> <i>(Link Only)</i></li> 
 
<li><a href = 'mergeSessionBeans.html'>Merge Session Beans</a> <i>(Link Only)</i></li> 
 
<li><a href = 'moveBusinessLogicToSession.html'>Move Business Logic to Session</a> <i>(Link Only)</i></li> 
 
<li><a href = 'moveClass.html'>Move Class</a> <i>by Gerard M. Davison</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'moveField.html'>Move Field</a> </li> 
 
<li><a href = 'moveMethod.html'>Move Method</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'parameterizeMethod.html'>Parameterize Method</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'preserveWholeObject.html'>Preserve Whole Object</a> </li> 
 
<li><a href = 'pullUpConstructorBody.html'>Pull Up Constructor Body</a> </li> 
 
<li><a href = 'pullUpField.html'>Pull Up Field</a> </li> 
 
<li><a href = 'pullUpMethod.html'>Pull Up Method</a> </li> 
 
<li><a href = 'pushDownField.html'>Push Down Field</a> </li> 
 
<li><a href = 'pushDownMethod.html'>Push Down Method</a> </li> 
 
<li><a href = 'reduceScopeOfVariable.html'>Reduce Scope of Variable</a> <i>by Mats Henricson</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'refactorArchitectureByTiers.html'>Refactor Architecture by Tiers</a> <i>(Link Only)</i></li> 
 
<li><a href = 'removeAssignmentsToParameters.html'>Remove Assignments to Parameters</a> </li> 
 
<li><a href = 'removeControlFlag.html'>Remove Control Flag</a> </li> 
 
<li><a href = 'removeDoubleNegative.html'>Remove Double Negative</a> <i>by Ashley Frieze and Martin Fowler</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'removeMiddleMan.html'>Remove Middle Man</a> </li> 
 
<li><a href = 'removeParameter.html'>Remove Parameter</a> </li> 
 
<li><a href = 'removeSettingMethod.html'>Remove Setting Method</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'renameMethod.html'>Rename Method</a> </li> 
 
<li><a href = 'replaceArrayWithObject.html'>Replace Array with Object</a> </li> 
 
<li><a href = 'replaceAssignmentWithInitialization.html'>Replace Assignment with Initialization</a> <i>by Mats
Henricson</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'replaceConditionalWithPolymorphism.html'>Replace Conditional with Polymorphism</a> </li> 
 
<li><a href = 'replaceConditionalWithVisitor.html'>Replace Conditional with Visitor</a> <i>by Ivan Mitrovic</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'replaceConstructorWithFactoryMethod.html'>Replace Constructor with Factory Method</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'replaceDataValueWithObject.html'>Replace Data Value with Object</a> </li> 
 
<li><a href = 'replaceDelegationWithInheritance.html'>Replace Delegation with Inheritance</a> </li> 
 
<li><a href = 'replaceErrorCodeWithException.html'>Replace Error Code with Exception</a> </li> 
 
<li><a href = 'replaceExceptionWithTest.html'>Replace Exception with Test</a> </li> 
 
<li><a href = 'replaceInheritanceWithDelegation.html'>Replace Inheritance with Delegation</a> </li> 
 
<li><a href = 'replaceIterationWithRecursion.html'>Replace Iteration with Recursion</a> <i>by Dave Whipp</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'replaceMagicNumberWithSymbolicConstant.html'>Replace Magic Number with Symbolic Constant</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'replaceMethodWithMethodObject.html'>Replace Method with Method Object</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'replaceNestedConditionalWithGuardClauses.html'>Replace Nested Conditional with Guard Clauses</a> </li> 
 
<li><a href = 'replaceParameterWithExplicitMethods.html'>Replace Parameter with Explicit Methods</a> </li> 
 
<li><a href = 'replaceParameterWithMethod.html'>Replace Parameter with Method</a> </li> 
 
<li><a href = 'replaceRecordWithDataClass.html'>Replace Record with Data Class</a> </li> 
 
<li><a href = 'replaceRecursionWithIteration.html'>Replace Recursion with Iteration</a> <i>by Ivan Mitrovic</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'replaceStaticVariableWithParameter.html'>Replace Static Variable with Parameter</a> <i>by Marian Vittek</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'replaceSubclassWithFields.html'>Replace Subclass with Fields</a> </li> 
 
<li><a href = 'replaceTempWithQuery.html'>Replace Temp with Query</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'replaceTypeCodeWithClass.html'>Replace Type Code with Class</a> <img src = 'updated.gif'></img></li> 
 
<li><a href = 'replaceTypeCodeWithStateStrategy.html'>Replace Type Code with State/Strategy</a> </li> 
 
<li><a href = 'replaceTypeCodeWithSubclasses.html'>Replace Type Code with Subclasses</a> </li> 
 
<li><a href = 'reverseConditional.html'>Reverse Conditional</a> <i>by Bill Murphy and Martin Fowler</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'selfEncapsulateField.html'>Self Encapsulate Field</a> </li> 
 
<li><a href = 'separateDataAccessCode.html'>Separate Data Access Code</a> <i>(Link Only)</i></li> 
 
<li><a href = 'separateQueryFromModifier.html'>Separate Query from Modifier</a> </li> 
 
<li><a href = 'splitLoop.html'>Split Loop</a> <i>by Martin Fowler</i><img src = 'new.gif'></img></li> 
 
<li><a href = 'splitTemporaryVariable.html'>Split Temporary Variable</a> </li> 
 
<li><a href = 'substituteAlgorithm.html'>Substitute Algorithm</a> </li> 
 
<li><a href = 'useAConnectionPool.html'>Use a Connection Pool</a> <i>(Link Only)</i></li> 
 
<li><a href = 'wrapEntitiesWithSession.html'>Wrap entities with session</a> <i>(Link Only)</i></li> 
"""

import re, string
refactor_name =  re.compile(r"href\s*=\s*'(\w+).html'")


def space_out_camel_case(s):
    """Adds _ to a camel case string.  Failure to space out string returns the original string.
    >>> space_out_camel_case('DMLSServicesOtherBSTextLLC')
    'DMLS Services Other BS Text LLC'
    """

    return re.sub('((?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z]))', '_', s)

#refactor_names = refactor_name.findall(src)
#print refactor_names

	

enum_template = string.Template(
"""package net.ericaro.neodocs;
// do not edit, generated by /src/main/python/refactoring.py

/** contains all kinds of refactoring techniques from <a href="http://refactoring.com/">Martin Fowler's Refactoring site</a>
* @see <a href="http://www.refactoring.com/catalog/">full list</a>
*
*/
public enum Refactoring {

$body

/**
* Please describe in a comment why none of the others refactoring matches.
*/
OTHER ,

}
"""
)

enum_body_template = string.Template(
"""	/**
	 * @see <a href="http://www.refactoring.com/catalog/$name.html">documentation</a>
	 */
	$uppername,
"""
)

body = ""
for name_match in refactor_name.finditer(src):
	name = name_match.group(1)
	uppername = space_out_camel_case(name).upper()
	body += enum_body_template.substitute(name=name, uppername=uppername)

source = enum_template.substitute(body=body)
with open('../java/net/ericaro/neodocs/Refactoring.java', 'w') as f:
	print >>f, source

print "done"




